<template>
    <div>
        <headerView class="box"></headerView>
        <div class="set_box">
            <div class="set_information">
                <h3>重置新密码</h3>
                <span>请输入新密码，并重新登录验证</span>
            </div>
            <div class="input_box">
                <input :type="showState" placeholder="请输入新密码" v-model="newPwd">
                <van-icon name="closed-eye" @click.stop="pwdState" v-if="iconShow" class="icon" />
                <van-icon name="browsing-history-o" v-else @click.stop="pwdState" class="icon" />
            </div>
            <van-button round id="btn" :disabled="nextState" @click="next">确定</van-button>
        </div>
    </div>
</template>

<script>
import { Toast, Notify } from 'vant';
import { changePassword } from "../../https/loginApi";
import headerView from "../../components/headerView.vue";
export default {
    components: { headerView },
    data() {
        return {
            nextState: false,
            sms: "",
            iconShow: true,
            showState: "password",
            newPwd: "",
            phoneNumber: "" // 手机号码
        }
    },
    created() {
        this.phoneNumber = this.$store.state.userNumber
        // console.log('重置密码',this.phoneNumber);
    },
    methods: {
        next() {
            let reg = /^(?!\D+$)(?![^a-zA-Z]+$)\S{6,20}$/
            // 发送请求修改密码, 如果后端需要一个手机号，到时候再写
            if (reg.test(this.newPwd)) {
                changePassword(this.phoneNumber, this.newPwd)
                    .then((res) => {
                        console.log('密码修改成功', res)
                        Toast.success('修改成功');
                        this.$router.push('/UserPwdLogin')
                    })
                    .catch((err) => {
                        console.log(err)
                        Notify({ type: 'danger', message: '验证码错误' });
                    })
                // Toast.success('修改成功');
                // this.$router.push('/UserPwdLogin')
                return
            }
            Notify({ type: 'danger', message: '密码包含6到20位之间的数字和字母' });
        },
        pwdState() {
            this.iconShow = !this.iconShow
            if (this.showState == 'text') {
                this.showState = 'password'
            } else {
                this.showState = 'text'
            }
        }
    }
}
</script>

<style scoped>
.box {
    background-color: #f8fafc;
    color: #000;
}

.set_box {
    width: 80%;
    margin: 0 auto;
}

h3 {
    font-weight: 300;
    margin: 0;
    margin-top: 20px;
}

.set_information p {
    font-size: 14px;
}

.set_information span {
    font-size: 12px;
    color: #cfccd6;
}

#btn {
    margin-top: 30px;
    width: 100%;
    background-color: #ff6e53;
    text-align: center;
    color: #ffff;
    font-size: 18px;
}

/* 输入框部分 */
.input_box {
    display: flex;
    width: 90%;
    /* margin: 0 auto; */
    margin: 50px auto;
    font-size: 15px;
    border-bottom: 1px solid #cfccd6;
}

.input_box input {
    border: none;
    width: 90%;
    padding: 15px 0;
}

input[type="password"]::-ms-reveal {
    display: none
}

.icon {
    color: #ff6e53;
    font-size: 20px;
    padding-right: 10px;
    line-height: 50px;
}

input::placeholder {
    color: #cfccd6;
    font-size: 15px;
    /* text-align: center; */
}
</style>